package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.service.ContentService;
import com.dongdongshop.vo.ContentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("content")
public class ContentController {

    @Autowired
    private ContentService cs;

    //查询全部
    @PostMapping("selectAll")
    public Result selectAll(){
        List<ContentVO> volist = cs.selectAll();
        return Result.OK().setData(volist);
    }

    //增加
    @PostMapping("addContent")
    public Result addContent(@RequestBody ContentVO vo){
        cs.addContent(vo);
        return Result.OK();
    }

    //回显
    @PostMapping("toUpdate")
    public Result toUpdate(Long id){
        ContentVO vo = cs.toUpdate(id);
        return Result.OK().setData(vo);
    }

    //修改
    @PostMapping("update")
    public Result update(@RequestBody ContentVO vo){
        cs.update(vo);
        return Result.OK();
    }

    //修改
    @PostMapping("deleteContent")
    public Result deleteContent(Long[] ids){
        cs.deleteContent(ids);
        return Result.OK();
    }

}
